using Avalonia.Controls;
using DataAnalysis.ViewModels;
using Microsoft.Extensions.DependencyInjection;

namespace DataAnalysis
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = App.Current.Services.GetService<MainViewModel>();
        }

        private async void ListBox_SelectionChanged(object? sender, Avalonia.Controls.SelectionChangedEventArgs e)
        {
            var vm = App.Current.Services.GetService<MainViewModel>();
            if (vm != null)
            {
                if(sender is ListBox listbox)
                {
                    if(listbox.SelectedItem == null)
                    {
                        return;
                    }
                    await vm.ReadMetaData(listbox.SelectedItem.ToString());
                }
            }
        }
    }
}